package com.jiepos.mpos.biz.code.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.code.service.AppCodeListService;
import com.jiepos.mpos.common.entity.App_Code_ListEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 * 
 * 
 * <p>标题: —— 系统参数控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @author 张学涛
 * @version 1.0
 * @since 2017年9月13日上午10:43:16
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("codelist")
public class AppCodeListController extends BaseController {
	
	@Autowired
	private AppCodeListService appCodeListService;
	
	/**
	 * 进入参数信息列表页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appCodeListEntity
	 * @return
	 */
	@RequestMapping("/getCodeList.do")
	public ModelAndView getCodeList(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination) {
		ModelAndView model = new ModelAndView("/module/code/codelist/code_list");		
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 查询参数列表信息json数据
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appCodeListEntity
	 * @return
	 */
	@RequestMapping("/getCodeListJson.do")
	public @ResponseBody Map getCodeListJson(Pagination pagination, App_Code_ListEntity appCodeListEntity) {
		return appCodeListService.getAppCodeList(pagination, appCodeListEntity)	;	
	}
	
	/**
	 * 进入参数信息详细页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param code_uuid
	 * @return
	 */
	@RequestMapping("/getCodeDetail.do")
	public ModelAndView getCodeDetail(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination,String code_uuid) {
		ModelAndView model = new ModelAndView("/module/code/codelist/code_detail");
		App_Code_ListEntity appCodeListEntity=appCodeListService.getCodeById(code_uuid);		
		model.addObject("appCodeListEntity", appCodeListEntity);
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 保存参数
	 * @param request
	 * @param response
	 * @param appCodeListEntity
	 * @return
	 */
	@RequestMapping("/saveCode.do")
	public ModelAndView saveCode(HttpServletRequest request, HttpServletResponse response,
			App_Code_ListEntity appCodeListEntity) {
		appCodeListService.saveCode(appCodeListEntity, super.getLoginUser(request, response));		
		Map map=super.getLoginUser(request, response);	
		return new ModelAndView(new RedirectView("getCodeList.do"), map);
	}

	/**
	 * 删除参数信息
	 * @param request
	 * @param response
	 * @param code_uuids
	 * @return
	 */
	@RequestMapping("/deleteCodeByIds.do")
	public ModelAndView deleteCodeByIds(HttpServletRequest request, HttpServletResponse response, String code_uuids) {
		appCodeListService.deleteCodeByIds(code_uuids);		
		Map map=super.getLoginUser(request, response);  
		return new ModelAndView(new RedirectView("getCodeList.do"), map);
	}
	
	/**
	 * 校验系统参数
	 * @param request
	 * @param response
	 * @param code_uuid
	 * @return
	 */
	@RequestMapping("/checkCode.do")
	public @ResponseBody String checkCode(App_Code_ListEntity appCodeListEntity){		
		return appCodeListService.checkCode(appCodeListEntity);
	}
}
